#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by master on 2017/4/18


from yinhang.HtmlDownLoader import HtmlDownloader
from bs4 import BeautifulSoup


class Save(object):
    @staticmethod
    def save(url, index, ws):
        download = HtmlDownloader()
        resp = download.download(url)

        soup = BeautifulSoup(resp, "lxml")

        title = soup.find('title').get_text()
        tr_list = soup.find('td', class_='hei14jj').find('table').find_all('tr')

        for i in range(len(tr_list)):
            soup2 = BeautifulSoup(str(tr_list[i]), 'lxml')
            td_list = soup2.find_all('td')
            if len(td_list) > 1:
                item = td_list[0].get_text()
                content = td_list[1].get_text()
                if index == 0:
                    ws.write(0, i-1, item)
                if content is not None:
                    ws.write(index+1, i - 1, content)
        print(index, title)
